﻿<%@ Page Title="JSON Test Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="JsonTestPage.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript" src="Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" src="Scripts/Utility.as.js"></script>
<script type="text/javascript" src="Scripts/TestClass.as.js"></script>
<script type="text/javascript">
    var test = new Alex.Library.Web.Ajax.Samples.TestClass();
    test.Option.ErrorHandler = function (XMLHttpRequest, status) {
        alert(XMLHttpRequest.responseText);
    };
    function TestSave() {
        test.Option.RequestType = 'POST';
        var objs = [
            { ID: 1, Name: "name1", Children: [
                { Keys: ["C#", "Java", "Delphi"], Order: 1 },
                { Keys: ["SQL Server", "Oracle", "Sybase", "DB2"], Order: 2 }
            ]
            },
            { ID: 2, Name: "name2", Children: [
                { Keys: ["Lenovo", "Dell", "HP", "Acer", "ThinkPad"], Order: 1 },
                { Keys: ["iPhone", "HTC", "Motolrola", "Nokia", "Samsung"], Order: 2 }
            ]
            },
            { ID: 2, Name: "name22" },
            { ID: 3, Name: "name3" }
        ];
        test.SaveObjects(objs, function (result) {            
            alert(result);
        });
    };
    function TestGet() {
        test.Option.RequestType = 'GET';
        test.GetTestObjects({ ID: 2 }, function (result) {
            $.each(result, function (i, item) {
                alert(item.Name);
                if (item.Children != null) {
                    alert(item.Name + " Children's Count:" + item.Children.length);
                    for (var i = 0; i < item.Children[0].Keys.length; i++) {
                        alert("Key-" + i + ":" + item.Children[0].Keys[i]);
                    }
                }
            });
        });
    };
    function TestStaticMethod() {
        test.Option.RequestType = 'GET';
        test.TestStaticMethod(function (result) {
            alert(result);
        });
    };
</script>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <h2>
        使用JSON作为返回值的DEMO
    </h2>
    <p>
        转到<a href="XmlTestPage.aspx" target="_self">XML测试页面</a>
    </p>
    <p>
        转到<a href="AjaxScript.aspx" target="_self">Ajax脚本生成器页面</a>
    </p>
    <input type="button" value="TestSave" onclick="TestSave();" />
    <input type="button" value="TestGet" onclick="TestGet();" />        
    <input type="button" value="TestStaticMethod" onclick="TestStaticMethod();" />    
</asp:Content>
